package com.raven.craft.code.generator.common.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author raven
 * @date 2019-03-22 19:12
 */
@Getter
@AllArgsConstructor
public enum KeyType implements BaseEnum<String> {

    PRIMARY_KEY("PRI"), // 主键
    UNIQUE("UNI"), // 唯一索引
    INDEX("MUL"), // 普通索引
    NULL("");

    @JsonValue
    @EnumValue
    private final String code;

    public Boolean isPK() {
        return PRIMARY_KEY.equals(this);
    }

    public Boolean isUnique() {
        return PRIMARY_KEY.equals(this) || UNIQUE.equals(this);
    }

    @Override
    public String toString() {
        return this == NULL ? "" : this.getCode();

    }
}
